import { createRouter, createWebHashHistory } from 'vue-router'


const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
   {path: '/', redirect: '/profile'}, 
   {path: '/profile', component: ()=>import('@/views/ProfileEdit.vue'), meta: {title: '个人中心'}},
   {path: '/address', component: ()=>import('@/views/AddressManager.vue'), meta: {
    title: '地址列表'
   }},
   {path: '/address/edit/:id?', component: ()=>import('@/views/AddressEdit.vue'), meta: {title: '编辑地址'}},
  ]
})

// 路由的全局前置守卫
router.beforeEach((to)=>{
  //  console.log('进入全局前置守卫', to);
    // 修改网页的标题
  document.title = to.meta.title as string
})

// 路由的全局后置守卫
// router.afterEach((to)=>{
//   // console.log('进入全局后置守卫', to);
//   // 修改网页的标题
//   // document.title = to.meta.title as string
// })

export default router
